package com.ruoyi.be.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.be.domain.MedicalCpoeArea;
import com.ruoyi.be.service.IMedicalCpoeAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病区管理Controller
 * 
 * @author cdj
 * @date 2022-01-04
 */
@RestController
@RequestMapping("/be/area")
public class MedicalCpoeAreaController extends BaseController
{
    @Autowired
    private IMedicalCpoeAreaService medicalCpoeAreaService;

    /**
     * 查询病区管理列表
     */
    @PreAuthorize("@ss.hasPermi('be:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalCpoeArea medicalCpoeArea)
    {
        startPage();
        List<MedicalCpoeArea> list = medicalCpoeAreaService.selectMedicalCpoeAreaList(medicalCpoeArea);
        return getDataTable(list);
    }

    /**
     * 导出病区管理列表
     */
    @PreAuthorize("@ss.hasPermi('be:area:export')")
    @Log(title = "病区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalCpoeArea medicalCpoeArea)
    {
        List<MedicalCpoeArea> list = medicalCpoeAreaService.selectMedicalCpoeAreaList(medicalCpoeArea);
        ExcelUtil<MedicalCpoeArea> util = new ExcelUtil<MedicalCpoeArea>(MedicalCpoeArea.class);
        util.exportExcel(response, list, "病区管理数据");
    }

    /**
     * 获取病区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('be:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(medicalCpoeAreaService.selectMedicalCpoeAreaById(id));
    }

    /**
     * 新增病区管理
     */
    @PreAuthorize("@ss.hasPermi('be:area:add')")
    @Log(title = "病区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalCpoeArea medicalCpoeArea)
    {
        medicalCpoeArea.setId(SecurityUtils.getUsername()+new Date().getTime());
        return toAjax(medicalCpoeAreaService.insertMedicalCpoeArea(medicalCpoeArea));
    }

    /**
     * 修改病区管理
     */
    @PreAuthorize("@ss.hasPermi('be:area:edit')")
    @Log(title = "病区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalCpoeArea medicalCpoeArea)
    {
        return toAjax(medicalCpoeAreaService.updateMedicalCpoeArea(medicalCpoeArea));
    }

    /**
     * 删除病区管理
     */
    @PreAuthorize("@ss.hasPermi('be:area:remove')")
    @Log(title = "病区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(medicalCpoeAreaService.deleteMedicalCpoeAreaByIds(ids));
    }
}
